home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / nodelist.c < prev    next >
C/C++ Source or Header  |  1994-11-15  |  6KB  |  294 lines

  1. /*
  2.  *                nodelist.c
  3.  *
  4.  * Generates list of rooms shared with each node.
  5.  */
  6.  
  7. /*
  8.  *                history
  9.  *
  10.  * 89Aug14 HAW  Handle virtual rooms as well.
  11.  * 87Dec06 HAW  Created.
  12.  */
  13.  
  14. #include "ctdl.h"    /* header file  */
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <math.h>
  19. #include <ctype.h>
  20. #include <time.h>
  21. #include <proto/exec.h>
  22. #include <dos/dos.h>
  23. #include <pragmas/dos_pragmas.h>
  24. #include "exec/memory.h"
  25. #include "exec/ports.h"
  26. #include "exec/exec.h"
  27.  
  28. /*
  29.  *                contents
  30.  *
  31.  *    crashout()        irrecoverable error
  32.  *    main()            Main controller for this program
  33.  *    openFile()        opens a .sys file
  34.  */
  35.  
  36. extern rTable *roomTab;        /* RAM index of rooms        */
  37. extern CONFIG cfg;        /* A buncha variables        */
  38. extern FILE    *netfl;
  39. extern NetBuffer netBuf;
  40. extern NetTable *netTab;
  41. extern VirtualRoom *VRoomTab;
  42. extern char VirtualInUse;
  43. extern VirtNet    *VirtNetList;
  44. extern int  thisNet, VirtSize, VNetSize;
  45. FILE *netLog;
  46.  
  47. int ListNodes(int alive);
  48. int ListByNodes(void);
  49. void CheckNet(int i, int roomSlot);
  50. void CheckVirt(int TheVirt, int NetRover);
  51. void PrintNetRooms(void);
  52. void PrintVirtuals(void);
  53.  
  54. /*
  55.  * crashout()
  56.  *
  57.  * This function handles an irrecoverable error.
  58.  */
  59. void crashout(str)
  60. char *str;
  61. {
  62.     exit(printf(str));
  63. }
  64.  
  65. /*
  66.  * main()
  67.  *
  68.  * This is the main controller.
  69.  */
  70. int main(int, char **);
  71. int main(argc, argv)
  72. int argc;
  73. char **argv;
  74. {
  75.     SYS_FILE netFile;
  76.     int Index, NetRover;
  77.  
  78.     cfg.weAre = UTILITY;
  79.     fprintf(stderr, "Node list generator, V3.41\n%s\n", COPYRIGHT);
  80.     if (readSysTab(FALSE, TRUE)) {
  81.     mvToHomeDisk(&cfg.homeArea);
  82.     makeSysName(netFile, "ctdlnet.sys", &cfg.netArea);
  83.     openFile(netFile, &netfl);
  84.     initNetBuf(&netBuf);
  85.  
  86.     if (argc != 1) {
  87.         if (strCmp(argv[1], "-n") == SAMESTRING)
  88.         return ListNodes(TRUE);
  89.         if (strCmp(argv[1], "-nd") == SAMESTRING)
  90.         return ListNodes(FALSE);
  91.         if (strCmp(argv[1], "-s") == SAMESTRING)
  92.         return ListByNodes();
  93.     }
  94.  
  95.     printf("%s\n", cfg.codeBuf + cfg.nodeName);
  96.     for (Index = AIDEROOM + 1;        /* First 3 never shared */
  97.         Index < MAXROOMS; Index++) {
  98.         if (  roomTab[Index].rtflags.INUSE &&
  99.             roomTab[Index].rtflags.SHARED) {
  100.         printf("%s\n", roomTab[Index].rtname);
  101.         for (NetRover = 0; NetRover < cfg.netSize; NetRover++) {
  102.             CheckNet(NetRover, Index);
  103.         }
  104.         printf("\n");
  105.         }
  106.     }
  107.     VirtInit();
  108.     if (VirtualInUse) {
  109.         for (Index = 0; Index < VirtSize; Index++) {
  110.         if (strLen(VRoomTab[Index].vrName) != 0) {
  111.             printf("%s (Virtual)\n", VRoomTab[Index].vrName);
  112.             for (NetRover = 0; NetRover < cfg.netSize; NetRover++) {
  113.             CheckVirt(Index, NetRover);
  114.             }
  115.             printf("\n");
  116.         }
  117.         }
  118.     }
  119.     }
  120. }
  121.  
  122. /*
  123.  * CheckVirt()
  124.  *
  125.  * This processes a virtual room.
  126.  */
  127. void CheckVirt(int TheVirt, int NetRover)
  128. {
  129.     int i;
  130.  
  131.     for (i = 0; i < VIRT_LIMIT; i++) {
  132.     if (VirtNetList[NetRover].VirtList[i].WhichVirt == TheVirt) {
  133.         getNet(NetRover, &netBuf);
  134.         if (netBuf.nbflags.in_use) {
  135.         printf("        %s", netBuf.netName);
  136.         switch (GetMode(VirtNetList[NetRover].VirtList[i].mode)) {
  137.             case PEON: printf(" (Peon)\n"); break;
  138.             case ACTIVE_BACKBONE:
  139.             printf(" (Backbone - Active)\n"); break;
  140.             case PASS_BACKBONE:
  141.             printf(" (Backbone - Passive)\n"); break;
  142.         }
  143.         }
  144.     }
  145.     }
  146. }
  147.  
  148. /*
  149.  * CheckNet()
  150.  *
  151.  * This checks to see if the given room is shared with this node and does
  152.  * the requisite print.
  153.  */
  154. void CheckNet(i, roomSlot)
  155. int i, roomSlot;
  156. {
  157.     int j;
  158.  
  159.     if (netTab[i].ntflags.in_use) {
  160.     for (j = 0; j < SHARED_ROOMS; j++) {
  161.         if (isSharedRoom(i, j)) {
  162.         if (netTabRoomSlot(i, j) == roomSlot &&
  163.             roomTab[roomSlot].rtgen == netGen(i, j)) {
  164.             getNet(i, &netBuf);
  165.             printf("        %s", netBuf.netName);
  166.             if (roomTab[netRoomSlot(j)].rtShareType == PEON)
  167.             printf(" (Peon)\n");
  168.             else switch (GetMode(netTab[i].netTRooms[j].mode)) {
  169.             case PEON:
  170.             printf(" (Peon)\n");    break;
  171.             case ACTIVE_BACKBONE:
  172.             printf(" (Active Backbone)\n");    break;
  173.             case PASS_BACKBONE:
  174.             printf(" (Passive Backbone)\n");    break;
  175.             }
  176.             return;
  177.         }
  178.         }
  179.     }
  180.     }
  181. }
  182.  
  183. /*
  184.  * ListNodes()
  185.  *
  186.  * This just prints the list of nodes.  If alive is set, then only print those
  187.  * nodes not disabled.
  188.  */
  189. int ListNodes(alive)
  190. int alive;
  191. {
  192.     int i;
  193.     static char *bauds[] = {
  194.     "300", "1200", "2400", "4800", "9600", "14400", "19200", "38400", "57600"
  195.     };
  196.  
  197.     for (i = 0; i < cfg.netSize; i++) {
  198.     getNet(i, &netBuf);
  199.     if (netBuf.nbflags.in_use &&
  200.         (!alive || (netBuf.MemberNets & ALL_NETS))) {
  201.         printf("%3d. %-21s%-21s%-11s%s\n", i, netBuf.netName, netBuf.netId,
  202.         (netBuf.nbflags.local) ? "local" : "non-local",
  203.         bauds[netBuf.baudCode]);
  204.     }
  205.     }
  206. }
  207.  
  208. /*
  209.  * ListByNodes()
  210.  *
  211.  * This prints out nodes and the rooms shared.
  212.  */
  213. int ListByNodes()
  214. {
  215.     int i;
  216.  
  217.     VirtInit();
  218.     for (i = 0; i < cfg.netSize; i++) {
  219.     getNet(i, &netBuf);
  220.     if (netBuf.nbflags.in_use) {
  221.         if (CheckForShared()) {
  222.         printf("%s\n", netBuf.netName);
  223.         PrintNetRooms();
  224.         PrintVirtuals();
  225.         printf("\n");
  226.         }
  227.     }
  228.     }
  229.  
  230.     return 0;
  231. }
  232.  
  233. /*
  234.  * CheckForShared()
  235.  *
  236.  * This decides if this node has any shared rooms at all.
  237.  */
  238. int CheckForShared()
  239. {
  240.     int rover, x;
  241.  
  242.     for (rover = 0; rover < SHARED_ROOMS; rover++)
  243.     if (isSharedRoom(thisNet, rover) && roomValidate(thisNet, rover))
  244.         return TRUE;
  245.  
  246.     if (!VirtualInUse) return FALSE;
  247.  
  248.     for (rover = 0; rover < VIRT_LIMIT; rover++) {
  249.     x = VirtNetList[thisNet].VirtList[rover].WhichVirt;
  250.     if (x != -1 && (x >= VirtSize || x < 0 || !VRoomInuse(x)))
  251.         VirtNetList[thisNet].VirtList[rover].WhichVirt = -1;
  252.  
  253.     if ((x = VirtNetList[thisNet].VirtList[rover].WhichVirt) != -1)
  254.         return TRUE;
  255.     }
  256.     return FALSE;
  257. }
  258.  
  259. /*
  260.  * PrintNetRooms()
  261.  *
  262.  * This prints out all the net rooms for the current node.
  263.  */
  264. void PrintNetRooms()
  265. {
  266.     int rover;
  267.  
  268.     for (rover = 0; rover < SHARED_ROOMS; rover++)
  269.     if (isSharedRoom(thisNet, rover) && roomValidate(thisNet, rover))
  270.         printf("     %s\n", roomTab[netTabRoomSlot(thisNet, rover)].rtname);
  271. }
  272.  
  273. /*
  274.  * PrintVirtuals()
  275.  *
  276.  * This prints out all the virtual rooms for the current node.
  277.  */
  278. void PrintVirtuals()
  279. {
  280.     int rover, x;
  281.  
  282.     if (!VirtualInUse) return ;
  283.  
  284.     for (rover = 0; rover < VIRT_LIMIT; rover++) {
  285.     x = VirtNetList[thisNet].VirtList[rover].WhichVirt;
  286.     if (x != -1 && (x >= VirtSize || x < 0 || !VRoomInuse(x)))
  287.         VirtNetList[thisNet].VirtList[rover].WhichVirt = -1;
  288.  
  289.     if ((x = VirtNetList[thisNet].VirtList[rover].WhichVirt) != -1)
  290.         printf("     %s\n", VRoomTab[x].vrName);
  291.     }
  292. }
  293.  
  294.